<template>
  <section>
    <div class="custorm--modelbox goodsother-edit">
      <!-- <choose-path ref="choosepath" :changeEvt="chooseUrl" :tabType="tabType"></choose-path> -->
      <renohome-right-nav :custormItemData="custormItemData" @rightNavChange="rightNavChange" showChange="1"></renohome-right-nav>
      <section v-if="nrActive">
        <div class="edit-form-item">
          <div class="form-label">选择商品</div>
          <el-radio-group v-model="custormItemData.params.choostype">
            <el-radio label="1">手动选择</el-radio>
            <el-radio label="2">选择分类</el-radio>
            <el-radio label="3">选择分组</el-radio>
          </el-radio-group>
          <div v-if="custormItemData.params.choostype==1" class="inner">
            <div class="goodscol-add" @click="addChooseItem"><i class="el-icon-plus"></i> 添加</div>
            <div class="flex-row choose-item-lits">
              <div v-for="(item, index) in custormItemData.params.chooseItemList" :key="index" class="choose-item-child">
                <img :src="item.images[0]" alt="" class="small">
                <i class="delete el-icon-close" @click="delChooseItem(index)" style="font-size: 16px;"></i>
              </div>
            </div>
          </div>
          <section v-if="custormItemData.params.choostype==2">
            <div class="inner flex-row flex-align-c">
              <div style="margin:10px">分类</div>
              <div class="select-btn-box" @click="pathtoggle('cateid')"><i class="icon icon-fujian select-btn-icon"></i>
                <el-input class="my-link-input" readonly size="small" v-model="custormItemData.params.cateid" placeholder="请选择分类"></el-input>
              </div>
            </div>
            <div class="form-label" style="margin-top: 20px;">显示条数</div>
            <div class="flex-row flex-align-c">
              <el-slider :show-tooltip="false" style="width: 70%;" v-model="custormItemData.params.listitem" input-size="mini" :max="20" :min="1">
              </el-slider>
              <div class="coupon-showslider">{{custormItemData.params.listitem}}个</div>
            </div>
          </section>
          <section v-if="custormItemData.params.choostype==3">
            <div class="inner flex-row flex-align-c">
              <div style="margin:10px">分组</div>
              <div class="select-btn-box" @click="pathtoggle('groupid')"><i class="icon icon-fujian select-btn-icon"></i>
                <el-input class="my-link-input" readonly size="small" v-model="custormItemData.params.groupid" placeholder="请选择分组"></el-input>
              </div>
            </div>
            <div class="form-label" style="margin-top: 20px;">显示条数</div>
            <div class="flex-row flex-align-c">
              <el-slider :show-tooltip="false" style="width: 70%;" v-model="custormItemData.params.listitem" input-size="mini" :max="20" :min="1">
              </el-slider>
              <div class="coupon-showslider">{{custormItemData.params.listitem}}个</div>
            </div>
          </section>
        </div>

        <div class="edit-form-item" v-if="custormItemData.params.choostype==2||custormItemData.params.choostype==3">
          <div class="form-label">商品排序</div>
          <el-radio-group v-model="custormItemData.params.sort" style="margin-bottom:12px;">
            <el-radio label="1">千人千面</el-radio>
            <el-radio label="2">自定义排序</el-radio>
          </el-radio-group>
          <div v-if="custormItemData.params.sort==1"><span style="color: #f1495c">*</span>根据会员特征千人千面展现，可大幅提升点击和成交转化率。</div>
          <div v-if="custormItemData.params.sort==2">
            <el-select size="small" style="width:100%;" v-model="custormItemData.params.sortcustorm" placeholder="综合" @change="serchListData('change','editorcou')">
              <el-option label="综合" value="all">
              </el-option>
              <el-option label="按销量" value="sales">
              </el-option>
              <el-option label="价格降序" value="desc_price">
              </el-option>
              <el-option label="价格升序" value="asc_price">
              </el-option>
              <el-option label="访问量" value="view_num">
              </el-option>
              <el-option label="成交转化率" value="pay_num">
              </el-option>
            </el-select>
          </div>
        </div>

        <div class="edit-form-item">
          <div class="form-label">显示内容</div>
          <el-checkbox v-model="custormItemData.style.name">商品名称</el-checkbox>
          <el-checkbox v-model="custormItemData.style.price">商品价格</el-checkbox>
        </div>
        <div class="edit-form-item">
          <div class="form-label">购物车按钮</div>
          <el-radio-group v-model="custormItemData.style.buybtn">
            <el-radio label="1">显示</el-radio>
            <el-radio label="2">隐藏</el-radio>
          </el-radio-group>
          <div v-if="custormItemData.style.buybtn==1" class="stylebox flex-row flex-align-c">
            <span>样式</span>
            <div class="txbox" @click="changeStyle(1)" v-bind:class="{active:custormItemData.style.buybtnstyle==1}">
              <div class="cft"></div>
            </div>
            <div class="txbox" @click="changeStyle(2)" v-bind:class="{active:custormItemData.style.buybtnstyle==2}">
              <div class="yuan"></div>
            </div>
            <div class="txbox" @click="changeStyle(3)" v-bind:class="{active:custormItemData.style.buybtnstyle==3}">
              <div class="zft"></div>
            </div>
          </div>
        </div>
        <div class="edit-form-item">
          <div class="form-label">角标</div>
          <el-radio-group v-model="custormItemData.style.icon">
            <el-radio label="1">不显示</el-radio>
            <el-radio label="2">系统图标</el-radio>
          </el-radio-group>
          <div v-if="custormItemData.style.icon==2" class="stylebox flex-row flex-align-c">
            <span style="margin-right:13px;">文字</span>
            <el-input v-model="custormItemData.style.icontext" maxlength="2" size="mini">
              <i slot="suffix" style="line-height: 28px;">{{custormItemData.style.icontext.length}}/2</i>
            </el-input>
          </div>
        </div>
      </section>

      <section v-if="fgActive">
        <div class="es-form-item goods" style="border-bottom: 0px;">
          <div class="item-inner block " style="transform: scale(0.8) translate(-50px, -20px); width: 375px;"><label class="button-img block" @click="changePattern(1)" v-bind:class="{active:custormItemData.style.display==1}" style="border-color: rgb(237, 237, 237);">
              <div class="es-goods-group block three" style="padding: 0 16px;">
                <div class="es-goods-item">
                  <div data-text="推荐" class="image "><img :src="getPath('default_picture.png')" alt=""></div>
                </div>
                <div class="es-goods-item">
                  <div data-text="推荐" class="image "><img :src="getPath('default_picture.png')" alt=""></div>
                  <div class="detail">
                    <div style="display: flex;">
                      <div style="flex: 1 1 0%;">
                        <div class="price"><span class="text">￥<span>20.00</span></span></div>
                      </div> <span class="buy buybtn1">
                        购买
                      </span>
                    </div>
                  </div>
                </div>
                <div class="es-goods-item">
                  <div data-text="推荐" class="image "><img :src="getPath('default_picture.png')" alt=""></div>
                </div>
              </div>
            </label></div>
          <div class="item-inner block " style="transform: scale(0.8) translate(-50px, -55px); width: 375px;"><label class="button-img block" @click="changePattern(2)" v-bind:class="{active:custormItemData.style.display==2}" style="border-color: rgb(237, 237, 237); overflow: hidden;">
              <div class="es-goods-group block three2">
                <div class="es-goods-item">
                  <div data-text="推荐" class="image "><img :src="getPath('default_picture.png')" alt=""></div>
                  <div class="detail">
                    <div class="name line-hide">这里是商品标题</div>
                    <div style="display: flex;">
                      <div style="flex: 1 1 0%;">
                        <div class="price"><span class="text">￥<span>20.00</span></span></div>
                      </div>
                    </div>
                  </div>
                </div>
                <div class="es-goods-item">
                  <div data-text="推荐" class="image "><img :src="getPath('default_picture.png')" alt=""></div>
                  <div class="detail">
                    <div class="name line-hide">这里是商品标题</div>
                    <div style="display: flex;">
                      <div style="flex: 1 1 0%;">
                        <div class="price"><span class="text">￥<span>20.00</span></span></div>
                      </div>
                    </div>
                  </div>
                </div>
                <div class="es-goods-item">
                  <div data-text="推荐" class="image "><img :src="getPath('default_picture.png')" alt=""></div>
                  <div class="detail">
                    <div class="name line-hide">这里是商品标题</div>
                    <div style="display: flex;">
                      <div style="flex: 1 1 0%;">
                        <div class="price"><span class="text">￥<span>20.00</span></span></div>
                      </div>
                    </div>
                  </div>
                </div>
                <div class="es-goods-item">
                  <div data-text="推荐" class="image "><img :src="getPath('default_picture.png')" alt=""></div>
                  <div class="detail">
                    <div class="name line-hide">这里是商品标题</div>
                    <div style="display: flex;">
                      <div style="flex: 1 1 0%;">
                        <div class="price"><span class="text">￥<span>20.00</span></span></div>
                      </div>
                    </div>
                  </div>
                </div>
              </div>
            </label></div>
        </div>
      </section>
    </div>
  </section>
</template>

<script>
import defaultConfig from './utils/editConfig'
export default {
  mixins: [defaultConfig.mixins],
  props: {
    defaultConfig: {
      type: Object,
      default: function() {
        return defaultConfig
      }
    }
  },
  data() {
    return {
      nrActive: true,
      fgActive: false,
      tabType: ['home', 'ather']
    }
  },
  components: {

  },
  watch: {

  },
  mounted() { },
  methods: {
    addChooseItem() {
      this.tabType = [
        ['server'], 'server'
      ]
      this.pathCurrent = 'add'
      this.$refs.choosepath.pathTrigger()
    },
    delChooseItem(currentIndex) {
      if (this.custormItemData.params.chooseItemList.length > 1) {
        this.$alert('确定删除此组件？', '提示', {
          confirmButtonText: '确定',
          callback: action => {
            if (action === 'confirm') {
              this.custormItemData.params.chooseItemList.splice(currentIndex, 1)
              this.$message({
                type: 'success',
                message: `删除成功`
              })
            }
          }
        })
      } else {
        this.$message.error('删除失败，此商品至少保留一个！~')
      }
    },
    chooseUrl(url, serveritem) {
      if (this.pathCurrent !== -1) {
        if (serveritem) {
          console.log(serveritem)
          this.custormItemData.params.chooseItemList.push(serveritem)
        } else {
          this.custormItemData.params[this.pathCurrent] = url
        }
      } else {
        this.$message.error('选择失败，请重试')
      }
    },
    pathtoggle(pathCurrent) {
      this.tabType = [
        ['home', 'ather'], 'home'
      ]
      this.$refs.choosepath.pathTrigger()
      this.pathCurrent = pathCurrent
    },
    output() {
      if (
        Object.prototype.toString.call(this.changeEvt) === '[object Function]'
      ) {
        this.custormEditEvt()
      }
    },
    changeStyle(e) {
      this.$nextTick(() => {
        this.custormItemData.style.buybtnstyle = e
      })
    },
    changePattern(e) {
      this.$nextTick(() => {
        this.custormItemData.style.display = e
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.custorm--modelbox.goodsother-edit {
  .edit-form-item {
    border-bottom: 5px solid #f6f7f9;
    padding: 20px 23px;
    font-size: 12px;
  }

  .edit-form-item:last-child {
    border-bottom: 0;
  }

  .el-radio__label {
    font-size: 12px;
  }

  .el-checkbox__label {
    font-size: 12px;
  }

  .form-label {
    line-height: 1;
    color: #47565d;
    font-weight: bolder;
    margin-bottom: 20px !important;
  }

  .inner {
    margin-top: 12px;
    white-space: nowrap;
  }

  .goodscol-add {
    border: 1px solid #6b7685;
    line-height: 32px;
    height: 32px;
    border-radius: 4px;
    text-align: center;
    cursor: pointer;
  }

  .stylebox {
    background: #f6f7f9;
    padding: 10px 20px;
    border: 1px solid #eee;
    color: #999;
    margin-top: 30px;
    white-space: nowrap;
  }

  .txbox {
    border-radius: 3px;
    border: 1px solid transparent;
    margin: 0 15px 0 13px;
    padding: 5px;
    cursor: pointer;
  }

  .txbox.active {
    border-color: #409eff;
  }

  .zft {
    background: #dcdcdc;
    height: 15px;
    width: 15px;
    border-radius: 3px;
  }

  .cft {
    background: #dcdcdc;
    height: 15px;
    width: 25px;
    border-radius: 3px;
  }

  .yuan {
    background: #dcdcdc;
    height: 15px;
    width: 15px;
    border-radius: 15px;
  }

  .select-btn-box {
    background: #e8effc;
    cursor: pointer;
    border-radius: 5px;
    padding: 0 10px;
    height: 32px;
    line-height: 32px;
    width: 60%;
  }

  .select-btn-icon {
    line-height: 32px;
    float: left;
    margin-right: 5px;
  }

  .select-btn-text {
    line-height: 32px;
    display: inline-block;
    height: 32px;
    vertical-align: middle;
  }

  .el-slider__input {
    width: 105px;
  }

  .el-slider__runway.show-input {
    margin-right: 130px;
  }

  //风格
  .es-form-item:last-child {
    border-bottom: 0;
  }

  .es-form-item {
    border-bottom: 5px solid #f6f7f9;
    padding: 20px 23px;
    font-size: 12px;
  }

  .es-form-item .item-inner:first-of-type {
    margin-top: 0;
  }

  .es-form-item .item-inner {
    margin-top: 8px;
    position: relative;
    display: -webkit-box;
    display: -webkit-flex;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-align: center;
    -webkit-align-items: center;
    -ms-flex-align: center;
    align-items: center;
  }

  .block {
    display: block !important;
  }

  .es-form-item.goods .button-img {
    padding: 0;
  }

  .button-img.active {
    border-color: #fb6638 !important;
  }

  .button-img.block {
    width: 100%;
    position: relative;
    min-height: 32px;
    height: auto;
    padding: 10px;
    text-align: left;
  }

  .button-img {
    width: 32px;
    height: 32px;
    margin-right: 20px;
    cursor: pointer;
    border-radius: 4px;
    line-height: 36px;
    text-align: center;
    border: 1px solid transparent;
  }

  .es-goods-group.three {
    display: -webkit-box !important;
    display: -webkit-flex !important;
    display: -ms-flexbox !important;
    display: flex !important;
    -webkit-box-pack: center;
    -webkit-justify-content: center;
    -ms-flex-pack: center;
    justify-content: center;
    -webkit-box-align: center;
    -webkit-align-items: center;
    -ms-flex-align: center;
    align-items: center;
  }

  .es-goods-group.three .es-goods-item {
    width: 110px;
  }

  .es-goods-group.block .es-goods-item {
    width: 50%;
    float: left;
    border-bottom: 0;
    background: none;
    padding: 5px;
    display: block;
    border-radius: 2px;
  }

  .es-goods-group.block .es-goods-item {
    border-radius: 4px;
  }

  .es-goods-item {
    position: relative;
    height: auto;
    padding: 14px;
    background: #fff;
    display: -webkit-box;
    display: -webkit-flex;
    display: -ms-flexbox;
    display: flex;
  }

  .es-goods-group.block .es-goods-item .image {
    float: none;
  }

  .es-goods-group.block .es-goods-item .image {
    width: 100%;
    height: auto;
    margin: 0;
    background-position: 50%;
    background-repeat: no-repeat;
    background-size: cover;
  }

  .es-goods-item .image {
    height: 100px;
    width: 100px;
    float: left;
    background-size: cover;
    position: relative;
    background-repeat: no-repeat;
    background-position: 50%;
  }

  .es-goods-group.block.three .es-goods-item .image img {
    height: 100px;
  }

  .es-goods-group.block .es-goods-item .image img {
    width: 100%;
    display: block;
    max-width: 100%;
    max-height: 100%;
  }

  .button-img.block img {
    max-width: 100%;
    max-height: 100%;
    display: block;
  }

  .es-goods-item .image img {
    height: 100%;
    width: 100%;
    max-width: 100%;
    max-height: 100%;
    display: block;
  }

  .button-img img {
    max-width: 30px;
    max-height: 30px;
  }

  .es-goods-group.block.three .es-goods-item .detail {
    padding: 10px 6px;
  }

  .es-goods-group.block .es-goods-item .detail {
    padding: 8px;
    overflow: hidden;
    line-height: 1.5;
  }

  .es-goods-item .detail {
    -webkit-box-flex: 1;
    -webkit-flex: 1;
    -ms-flex: 1;
    flex: 1;
    line-height: 1.5;
    background: #fff;
    padding-left: 10px;
    display: flex;
    display: -webkit-box;
    display: -webkit-flex;
    display: -ms-flexbox;
    -webkit-box-orient: vertical;
    -ms-flex-direction: column;
    -webkit-flex-direction: column;
    flex-direction: column;
    -webkit-box-pack: justify;
    -ms-flex-pack: justify;
    -webkit-justify-content: space-between;
    justify-content: space-between;
  }

  .es-goods-item .detail .price {
    position: relative;
    display: -webkit-box;
    display: -webkit-flex;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-align: center;
    -webkit-align-items: center;
    -ms-flex-align: center;
    align-items: center;
    font-size: 14px;
  }

  .es-goods-item .detail .price .text {
    color: #fd463e;
    font-weight: 700;
  }

  .es-goods-item .detail .price .text {
    color: #f55;
    font-size: 13px;
  }

  .es-goods-group.three .es-goods-item .price .text span {
    font-size: 12px;
  }

  .es-goods-item .detail .buy.buybtn1 {
    border: 1px solid #f55;
    background: #f55;
  }

  .es-goods-item .detail .buy {
    display: inline-block;
    height: 20px;
    color: #fff;
    line-height: 22px;
    padding: 0;
    width: 32px;
    border-radius: 2px;
    text-align: center;
    border: 1px solid transparent;
    float: right;
    -webkit-align-self: flex-end;
    -ms-flex-item-align: end;
    align-self: flex-end;
  }

  .es-goods-group.block.three2 {
    width: 9999px;
  }

  .es-goods-group.block.three2 .es-goods-item {
    width: 100px;
  }

  .es-goods-group.block.three2 .es-goods-item img {
    height: 90px;
  }

  .es-goods-group.block.three2 .es-goods-item .price .text span {
    font-size: 12px;
  }
}
</style>
